<?php defined( '_VALID_MOS' ) or die( 'Warning: access denied !' );
class menuClass{
	public function loadMenu($parent_Id='', $menu_type_id='', $icon=''){
		$database = new database;	
		$sql = "select `Id`, CONCAT(`link` , `link_id`) as `link`, `title`, `type`, `target` 
		from `menu` where parent_Id = ? and `menu`.`menu_type_id` = ?  and `activated` = 1 order by order_num";
		$result = $database->mySqlOutputData($sql, array($parent_Id, $menu_type_id));
		$i = 0;
		while($row = $result->fetch()){
			if(isset($_GET["item"])){
				if($row["Id"] == $_GET["item"]){
					if($row["type"] == 'linkout'){
						$Menu .= '<li class="isactive">' . $icon . '<a class="isactive" target="' . $row["target"] . '" href="' . $row["link"] . '"> ' . $row["title"] . '</a>';
						$Menu .= menuClass::loadSubMemu($row["Id"], $menu_type_id, $icon);
						$Menu .= '</li>';
					} else {
						$Menu .= '<li class="isactive">' . $icon . '<a class="isactive" target="' . $row["target"] . '" href="' . $row["link"] . '/' .$row["Id"] . '.csp"> ' . $row["title"] . '</a>';
						$Menu .= menuClass::loadSubMemu($row["Id"], $menu_type_id, $icon);
						$Menu .= '</li>';
					}
				} else {
					if($row["type"] == 'linkout'){
						$Menu .= '<li>' . $icon . '<a target="' . $row["target"] . '" href="' . $row["link"] . '"> ' . $row["title"] . '</a>';
						$Menu .= menuClass::loadSubMemu($row["Id"], $menu_type_id, $icon);
						$Menu .= '</li>';
					} else {
						$Menu .= '<li>' . $icon . '<a target="' . $row["target"] . '" href="' . $row["link"] . '/' .$row["Id"] . '.csp"> ' . $row["title"] . '</a>';
						$Menu .= menuClass::loadSubMemu($row["Id"], $menu_type_id, $icon);
						$Menu .= '</li>';
					}
				}
			} else {
				if($row["type"] == 'linkout'){
					if($i == 0){
						$Menu .= '<li class="isactive">' . $icon . '<a class="isactive" target="' . $row["target"] . '" href="' . $row["link"] . '"> ' . $row["title"] . '</a>';
						$Menu .= menuClass::loadSubMemu($row["Id"], $menu_type_id, $icon);
						$Menu .= '</li>';
					} else {
						$Menu .= '<li>' . $icon . '<a target="' . $row["target"] . '" href="' . $row["link"] . '"> ' . $row["title"] . '</a>';
						$Menu .= menuClass::loadSubMemu($row["Id"], $menu_type_id, $icon);
						$Menu .= '</li>';
					}
				} else {
					$Menu .= '<li>' . $icon . '<a target="' . $row["target"] . '" href="' . $row["link"] . '/' .$row["Id"] . '.csp"> ' . $row["title"] . '</a>';
					$Menu .= menuClass::loadSubMemu($row["Id"], $menu_type_id, $icon);
					$Menu .= '</li>';
				}
			}
			$i++;
		}
		return $Menu;		
	}
						
	public function loadSubMemu($id='', $menu_type_id='', $icon=''){
		$database = new database;
		$sql = "select `Id`, CONCAT(`link` , `link_id`) as `link`, `title`, `type`, `target` 
		from `menu` where parent_Id = ? and `menu`.`menu_type_id` = ? and `activated` = 1  order by order_num ";
		$result = $database->mySqlOutputData($sql, array($id, $menu_type_id));
		if($result->rowCount() > 0){
			$Sub_Menu .=  '<ul>';
			while($row = $result->fetch()){
				if($row["type"] == 'linkout'){
					$Sub_Menu .='<li><a target="' . $row["target"] . '" href="' . $row["link"] . '">' . $row["title"] . '</a>';
					$Sub_Menu .= menuClass::loadSubMemu($row["Id"], $menu_type_id, $icon);
					$Sub_Menu .= "</li>";
				} else {
					$Sub_Menu .='<li><a target="' . $row["target"] . '" href="' . $row["link"] . '/' . $row["Id"] . '.csp">' . $row["title"] . '</a>';
					$Sub_Menu .= menuClass::loadSubMemu($row["Id"], $menu_type_id, $icon);
					$Sub_Menu .= "</li>";
				}
			}
			$Sub_Menu .= '</ul>';
		}
		return $Sub_Menu;
	}
}
?>